﻿<template>
  <div class="personal">
    <el-form label-width="100px" ref="editForm" :model="editForm" :rules="rules">
      <el-form-item label="楼号" prop="louhao">
        <el-input size="small" v-model="editForm.louhao" auto-complete="off" placeholder="请输入楼号"
                  style='width:50%'></el-input>
      </el-form-item>
      <el-form-item label="教室号" prop="sushehao">
        <el-input size="small" v-model="editForm.sushehao" auto-complete="off" placeholder="请输入教室号"
                  style='width:50%'></el-input>
      </el-form-item>
      <el-form-item label="教室管" prop="suguan">
<!--        <el-input size="small" v-model="editForm.suguan" auto-complete="off" placeholder="请输入教室管"-->
<!--                  style='width:50%'></el-input>-->
        <el-select v-model="editForm.suguan" placeholder="请选择">
          <el-option
              v-for="item in suguanList"
              :key="item.id"
              :label="item.mingzi"
              :value="item.mingzi">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="院系" prop="yuanxi">
        <el-input size="small" v-model="editForm.yuanxi" auto-complete="off" placeholder="请输入院系" style='width:50%'
                  ></el-input>
      </el-form-item>
      <el-form-item label='类型' prop="leixing">
        <el-select size="small" v-model="editForm.leixing" placeholder="请选择类型">
          <el-option selected label="请选择类型" value=""></el-option>
          <el-option label="男生教室" value="男生教室"></el-option>
          <el-option label="女生教室" value="女生教室"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="beizhu">
        <el-input type="textarea" size="small" v-model="editForm.beizhu" auto-complete="off" placeholder="请输入备注"
                  style='width:100%'></el-input>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">添加
      </el-button>
    </div>
  </div>
</template>

<script>
import {louyuxinxiEdit, louyuxinxiSave, louyuxinxiDetail} from "@/api/louyuxinxi/louyuxinxiApi";
import {Session} from "@/utils/storage";
import {xueshengxinxiDetail, xueshengxinxiEdit} from "../../api/xueshengxinxi/xueshengxinxiApi";
import {suguanxinxiAllList} from "../../api/suguanxinxi/suguanxinxiApi"
//xiabiaoduan1
export default {
  name: 'personal',
  data() {
    return {
      rules: {
        //yztssssss1
      },
      editForm: {
        avater: '',
        louhao: '',
        yuanxi: '',

      },
      username: '',
      cx: '',
      suguanList:{}
      //xiabiaoduan2
    };
  },
  created() {
    if (!Session.get('userInfo')) return false;
    this.userInfo = Session.get('userInfo');
    this.username = localStorage.getItem("username");
    this.cx = localStorage.getItem("cx");
    let id = this.$route.params.id;
    //xiabiaoduan3
    this.getUserInfo(id);
    this.getSuguanxinxiAll()
  },
  computed: {
    headers() {
      return {"token": Session.get("token")}
    },
  },
  methods: {
    getSuguanxinxiAll(){
      suguanxinxiAllList().then(res =>{
        if (res.code == '0'){
          this.suguanList=res.data
        }
      })
    },

    getSuguan(val){
      this.editForm.suguan=val.mingzi
    },

    getUserInfo(id) {
      xueshengxinxiDetail(id).then(res => {
        if (res.code == '0') {
          this.xueshengxinxi = res.data
          this.editForm.louhao = this.xueshengxinxi.louhao;
          this.editForm.yuanxi = this.xueshengxinxi.yuanxi;

          this.editForm.louhao = this.userInfo.xuehao;


        }
      })
    },

    //qixuzhijixsuan3
    //xia2sui1
    // 编辑、增加页面保存方法
    submitForm(editData) {

      this.$refs[editData].validate(valid => {
        if (valid) {
          if (this.editForm.id) {

          } else {
            louyuxinxiSave(this.editForm).then(res => {
              if (res.code == '0') {

                this.$message({
                  type: 'success',
                  message: '添加成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            }).catch(err => {
              if (err) {
                this.$message.error(err)
              } else {
                this.$message.error('操作失败，请稍后再试！')
              }
            })
          }
        } else {
          return false
        }
      })
    },

    //youscwexnjiaxn
    //xiabiaoduan4
  }
};
</script>

<style scoped lang="scss">
@import './index.scss';
</style>
